package com.yc.yyds.biz;

import com.yc.yyds.dao.UserLoginDao;
import com.yc.yyds.dao.UserMsgDao;

import java.util.Map;

public class UserLoginBiz {
    UserLoginDao dao = new UserLoginDao();
    UserMsgDao userDao = new UserMsgDao();
    public Map<String,Object> userLogin(String userzh,String pwd) throws BizException {
        Map<String, Object> user = dao.userMsg(userzh, pwd);
        if (user!=null){
            return user;
        }else {
            throw new BizException("用户名或密码错误");
        }
    }
    public Map<String,Object> userPhoneLogin(String phone) throws BizException {
        final Map<String, Object> user = dao.userPhoneMsg(phone);
        if (user!=null){
            return user;
        }else {
            throw new BizException("该用户不存在");
        }
    }
    //修改用户信息
    public void save(String username,String pwd,String phone,String email,String image,String gender,String userid) throws BizException {
        if (username.isEmpty()){
            throw new BizException("昵称不能为空");
        }
        if (pwd.isEmpty()){
            throw new BizException("密码不能为空");
        }
        if (pwd.length()<6){
            throw new BizException("密码不能少于6位");
        }
        if (phone.isEmpty()){
            throw new BizException("手机号不能为空");
        }
        if (email.isEmpty()){
            throw new BizException("邮箱不能为空");
        }
        if (userid.isEmpty()){
            throw new BizException("业务异常,稍后再试");
        }
        try {
            userDao.save(username, pwd, phone, email, image, gender, userid);
        }catch (Exception e){
            throw new BizException("业务异常,稍后再试");
        }
    }
}
